{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> start QUANTAXIS\n",
      "QUANTAXIS>> Welcome to QUANTAXIS, the Version is 1.0.65\n",
      "QUANTAXIS>>  \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``########`````##````````##``````````##`````````####````````##```##########````````#``````##``````###```##`````######`` \n",
      "  `##``````## ```##````````##`````````####````````##`##```````##```````##```````````###``````##````##`````##```##`````##` \n",
      "  ##````````##```##````````##````````##`##````````##``##``````##```````##``````````####```````#```##``````##```##``````## \n",
      "  ##````````##```##````````##```````##```##```````##```##`````##```````##`````````##`##```````##`##```````##````##``````` \n",
      "  ##````````##```##````````##``````##`````##``````##````##````##```````##````````##``###```````###````````##`````##`````` \n",
      "  ##````````##```##````````##``````##``````##`````##`````##```##```````##```````##````##```````###````````##``````###```` \n",
      "  ##````````##```##````````##`````##````````##````##``````##``##```````##``````##``````##`````##`##```````##````````##``` \n",
      "  ##````````##```##````````##````#############````##```````##`##```````##`````###########`````##``##``````##`````````##`` \n",
      "  ###```````##```##````````##```##```````````##```##```````##`##```````##````##`````````##```##```##``````##```##`````##` \n",
      "  `##``````###````##``````###``##`````````````##``##````````####```````##```##``````````##``###````##`````##````##`````## \n",
      "  ``#########``````########```##``````````````###`##``````````##```````##``##````````````##`##``````##````##`````###``### \n",
      "  ````````#####`````````````````````````````````````````````````````````````````````````````````````````````````````##``  \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``````````````````````````Copyright``yutiansut``2018``````QUANTITATIVE FINANCIAL FRAMEWORK````````````````````````````` \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " \n"
     ]
    }
   ],
   "source": [
    "import QUANTAXIS as QA\n",
    "import random\n",
    "market = QA.QA_Market()\n",
    "user = QA.QA_Portfolio()\n",
    "# 创建两个account\n",
    "# 这里是创建一个资产组合,然后在组合里面创建两个account  你可以想象成股票里面的两个策略账户\n",
    "# 然后返回的是这个账户的id\n",
    "a_1 = user.new_account()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account Acc_6FYolQth>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<QA_Market with ['backtest'] QA_Broker >\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n",
      "< QA_Order realorder_id Order_xNF7jTOS datetime:2017-01-04 09:31:00 code:000002 amount:1000 price:20.85 towards:1 btype:stock_cn order_id:Order_xNF7jTOS account:Acc_6FYolQth status:300 >\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n",
      "< QA_Order realorder_id Order_HSXGokPv datetime:2017-01-05 09:31:00 code:000002 amount:1000 price:20.93 towards:1 btype:stock_cn order_id:Order_HSXGokPv account:Acc_6FYolQth status:300 >\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000007 date 2017-01-16 price None order_model CLOSE amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "< QA_Order realorder_id Order_OsaBy2zu datetime:2017-01-05 09:31:00 code:000004 amount:1000 price:44.44 towards:1 btype:stock_cn order_id:Order_OsaBy2zu account:Acc_6FYolQth status:300 >===== SETTLED None =====\n",
      "\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order realorder_id Order_07nBUeLG datetime:2017-01-06 09:31:00 code:000001 amount:1000 price:9.13 towards:1 btype:stock_cn order_id:Order_07nBUeLG account:Acc_6FYolQth status:300 >\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> code 000007 date 2017-01-18 price None order_model CLOSE amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "< QA_Order realorder_id Order_2SacPF4Z datetime:2017-01-09 09:31:00 code:000002 amount:1000 price:20.66 towards:1 btype:stock_cn order_id:Order_2SacPF4Z account:Acc_6FYolQth status:300 >\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> MARKET WARING: SOMEING WRONG WITH ORDER \n",
      " \n",
      "QUANTAXIS>> code 000007 date 2017-01-19 price None order_model CLOSE amount_model by_amount\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===== SETTLED None =====\n",
      "< QA_Order realorder_id Order_NvhOeWqH datetime:2017-01-12 09:31:00 code:000001 amount:1000 price:9.15 towards:1 btype:stock_cn order_id:Order_NvhOeWqH account:Acc_6FYolQth status:300 >\n",
      "===== SETTLED None =====\n",
      "< QA_Order realorder_id Order_MZcslPuQ datetime:2017-01-17 09:31:00 code:000002 amount:1000 price:20.8 towards:1 btype:stock_cn order_id:Order_MZcslPuQ account:Acc_6FYolQth status:300 >\n",
      "===== SETTLED None =====\n",
      "< QA_Order realorder_id Order_KfpYI4M0 datetime:2017-01-18 09:31:00 code:000002 amount:1000 price:20.92 towards:1 btype:stock_cn order_id:Order_KfpYI4M0 account:Acc_6FYolQth status:300 >\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n",
      "===== SETTLED None =====\n",
      "[['2017-01-04 15:00:00', '000002', 20.85, 1000.0, 979144.7875, 'Order_xNF7jTOS', 'Trade_2pDrT1iL', 'Acc_6FYolQth', 5.2125, 0.0], ['2017-01-05 15:00:00', '000002', 20.93, 1000.0, 958209.5549999999, 'Order_HSXGokPv', 'Trade_PVO3Twz9', 'Acc_6FYolQth', 5.2325, 0.0], ['2017-01-05 15:00:00', '000004', 44.44, 1000.0, 913758.445, 'Order_OsaBy2zu', 'Trade_1qQutHdA', 'Acc_6FYolQth', 11.11, 0.0], ['2017-01-06 15:00:00', '000001', 9.13, 1000.0, 904623.445, 'Order_07nBUeLG', 'Trade_r4LNcOPy', 'Acc_6FYolQth', 5.0, 0.0], ['2017-01-09 15:00:00', '000002', 20.66, 1000.0, 883958.2799999999, 'Order_2SacPF4Z', 'Trade_Ih7aGYPH', 'Acc_6FYolQth', 5.165, 0.0], ['2017-01-12 15:00:00', '000001', 9.15, 1000.0, 874803.2799999999, 'Order_NvhOeWqH', 'Trade_0LtSHdIY', 'Acc_6FYolQth', 5.0, 0.0], ['2017-01-17 15:00:00', '000002', 20.8, 1000.0, 853998.08, 'Order_MZcslPuQ', 'Trade_V2iHtgjv', 'Acc_6FYolQth', 5.200000000000001, 0.0], ['2017-01-18 15:00:00', '000002', 20.92, 1000.0, 833072.85, 'Order_KfpYI4M0', 'Trade_IfTMl7VW', 'Acc_6FYolQth', 5.23, 0.0]]\n",
      "[1000000, 979144.7875, 958209.5549999999, 913758.445, 904623.445, 883958.2799999999, 874803.2799999999, 853998.08, 833072.85]\n",
      "833072.85\n",
      "< QA_Order realorder_id Order_jS9se3y5 datetime:2017-01-18 09:31:00 code:000004 amount:1000 price:37.15 towards:1 btype:stock_cn order_id:Order_jS9se3y5 account:Acc_6FYolQth status:300 >\n",
      "              datetime    code  price  amount         cash        order_id  \\\n",
      "0  2017-01-04 15:00:00  000002  20.85  1000.0  979144.7875  Order_xNF7jTOS   \n",
      "1  2017-01-05 15:00:00  000002  20.93  1000.0  958209.5550  Order_HSXGokPv   \n",
      "2  2017-01-05 15:00:00  000004  44.44  1000.0  913758.4450  Order_OsaBy2zu   \n",
      "3  2017-01-06 15:00:00  000001   9.13  1000.0  904623.4450  Order_07nBUeLG   \n",
      "4  2017-01-09 15:00:00  000002  20.66  1000.0  883958.2800  Order_2SacPF4Z   \n",
      "5  2017-01-12 15:00:00  000001   9.15  1000.0  874803.2800  Order_NvhOeWqH   \n",
      "6  2017-01-17 15:00:00  000002  20.80  1000.0  853998.0800  Order_MZcslPuQ   \n",
      "7  2017-01-18 15:00:00  000002  20.92  1000.0  833072.8500  Order_KfpYI4M0   \n",
      "\n",
      "         trade_id account_cookie  commission  tax  \n",
      "0  Trade_2pDrT1iL   Acc_6FYolQth      5.2125  0.0  \n",
      "1  Trade_PVO3Twz9   Acc_6FYolQth      5.2325  0.0  \n",
      "2  Trade_1qQutHdA   Acc_6FYolQth     11.1100  0.0  \n",
      "3  Trade_r4LNcOPy   Acc_6FYolQth      5.0000  0.0  \n",
      "4  Trade_Ih7aGYPH   Acc_6FYolQth      5.1650  0.0  \n",
      "5  Trade_0LtSHdIY   Acc_6FYolQth      5.0000  0.0  \n",
      "6  Trade_V2iHtgjv   Acc_6FYolQth      5.2000  0.0  \n",
      "7  Trade_IfTMl7VW   Acc_6FYolQth      5.2300  0.0  < QA_Order realorder_id Order_AzHMUgxZ datetime:2017-01-19 09:31:00 code:000002 amount:1000 price:20.6 towards:1 btype:stock_cn order_id:Order_AzHMUgxZ account:Acc_6FYolQth status:300 >\n",
      "\n",
      "code\n",
      "000001    2000.0\n",
      "000002    5000.0\n",
      "000004    2000.0\n",
      "Name: amount, dtype: float64\n",
      "< QA_Order realorder_id Order_dEsC8GmL datetime:2017-01-20 09:31:00 code:000001 amount:1000 price:9.22 towards:1 btype:stock_cn order_id:Order_dEsC8GmL account:Acc_6FYolQth status:300 >\n"
     ]
    }
   ],
   "source": [
    "market.start()\n",
    "market.connect(QA.RUNNING_ENVIRONMENT.BACKETEST)\n",
    "\n",
    "# 打印market\n",
    "print(market)\n",
    "\n",
    "\n",
    "\"\"\"\n",
    "登陆到这个交易前置上 把你刚才的两个账户\n",
    "\"\"\"\n",
    "# 登陆交易\n",
    "market.login(QA.BROKER_TYPE.BACKETEST, a_1.account_cookie, a_1)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "for date in QA.QA_util_get_trade_range('2017-01-01','2017-01-31'):\n",
    "    for code in ['000001', '000002', '000004', '000007']:\n",
    "        if random.random()<0.3:\n",
    "            market.insert_order(account_cookie=a_1.account_cookie, amount=1000, price=None, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT, time=date, code=code,\n",
    "                                order_model=QA.ORDER_MODEL.CLOSE, towards=QA.ORDER_DIRECTION.BUY, market_type=QA.MARKET_TYPE.STOCK_CN,\n",
    "                                frequence=QA.FREQUENCE.DAY, broker_name=QA.BROKER_TYPE.BACKETEST)\n",
    "        else:\n",
    "            try:\n",
    "                print(user.get_account(a_1.account_cookie).sell_available.get(code,0))\n",
    "                market.insert_order(account_cookie=a_1.account_cookie, amount=1000, price=None, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT, time=date, code=code,\n",
    "                                    order_model=QA.ORDER_MODEL.CLOSE, towards=QA.ORDER_DIRECTION.SELL, market_type=QA.MARKET_TYPE.STOCK_CN,\n",
    "                                    frequence=QA.FREQUENCE.DAY, broker_name=QA.BROKER_TYPE.BACKETEST)\n",
    "            except:\n",
    "                pass\n",
    "    \n",
    "    market._settle(QA.BROKER_TYPE.BACKETEST)\n",
    "        \n",
    "\n",
    "print(a_1.history)\n",
    "print(a_1.cash)\n",
    "print(a_1.cash_available)\n",
    "print(a_1.history_table)\n",
    "print(a_1.hold)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order realorder_id Order_E0NeS1Ci datetime:2017-01-20 09:31:00 code:000002 amount:1000 price:20.68 towards:1 btype:stock_cn order_id:Order_E0NeS1Ci account:Acc_6FYolQth status:300 >\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-04 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.85</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>979144.7875</td>\n",
       "      <td>Order_xNF7jTOS</td>\n",
       "      <td>Trade_2pDrT1iL</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2125</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-05 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.93</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>958209.5550</td>\n",
       "      <td>Order_HSXGokPv</td>\n",
       "      <td>Trade_PVO3Twz9</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2325</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-05 15:00:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>44.44</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>913758.4450</td>\n",
       "      <td>Order_OsaBy2zu</td>\n",
       "      <td>Trade_1qQutHdA</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>11.1100</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-06 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.13</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>904623.4450</td>\n",
       "      <td>Order_07nBUeLG</td>\n",
       "      <td>Trade_r4LNcOPy</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.0000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-09 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.66</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>883958.2800</td>\n",
       "      <td>Order_2SacPF4Z</td>\n",
       "      <td>Trade_Ih7aGYPH</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.1650</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-01-12 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>874803.2800</td>\n",
       "      <td>Order_NvhOeWqH</td>\n",
       "      <td>Trade_0LtSHdIY</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.0000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2017-01-17 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.80</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>853998.0800</td>\n",
       "      <td>Order_MZcslPuQ</td>\n",
       "      <td>Trade_V2iHtgjv</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2017-01-18 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.92</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>833072.8500</td>\n",
       "      <td>Order_KfpYI4M0</td>\n",
       "      <td>Trade_IfTMl7VW</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2300</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2017-01-18 15:00:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>795913.5625</td>\n",
       "      <td>Order_jS9se3y5</td>\n",
       "      <td>Trade_bknV2DhH</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>9.2875</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2017-01-19 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.60</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>775308.4125</td>\n",
       "      <td>Order_AzHMUgxZ</td>\n",
       "      <td>Trade_sFdUk0Ji</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.1500</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2017-01-20 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.22</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>766083.4125</td>\n",
       "      <td>Order_dEsC8GmL</td>\n",
       "      <td>Trade_806H7Z5V</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.0000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               datetime    code  price  amount         cash        order_id  \\\n",
       "0   2017-01-04 15:00:00  000002  20.85  1000.0  979144.7875  Order_xNF7jTOS   \n",
       "1   2017-01-05 15:00:00  000002  20.93  1000.0  958209.5550  Order_HSXGokPv   \n",
       "2   2017-01-05 15:00:00  000004  44.44  1000.0  913758.4450  Order_OsaBy2zu   \n",
       "3   2017-01-06 15:00:00  000001   9.13  1000.0  904623.4450  Order_07nBUeLG   \n",
       "4   2017-01-09 15:00:00  000002  20.66  1000.0  883958.2800  Order_2SacPF4Z   \n",
       "5   2017-01-12 15:00:00  000001   9.15  1000.0  874803.2800  Order_NvhOeWqH   \n",
       "6   2017-01-17 15:00:00  000002  20.80  1000.0  853998.0800  Order_MZcslPuQ   \n",
       "7   2017-01-18 15:00:00  000002  20.92  1000.0  833072.8500  Order_KfpYI4M0   \n",
       "8   2017-01-18 15:00:00  000004  37.15  1000.0  795913.5625  Order_jS9se3y5   \n",
       "9   2017-01-19 15:00:00  000002  20.60  1000.0  775308.4125  Order_AzHMUgxZ   \n",
       "10  2017-01-20 15:00:00  000001   9.22  1000.0  766083.4125  Order_dEsC8GmL   \n",
       "\n",
       "          trade_id account_cookie  commission  tax  \n",
       "0   Trade_2pDrT1iL   Acc_6FYolQth      5.2125  0.0  \n",
       "1   Trade_PVO3Twz9   Acc_6FYolQth      5.2325  0.0  \n",
       "2   Trade_1qQutHdA   Acc_6FYolQth     11.1100  0.0  \n",
       "3   Trade_r4LNcOPy   Acc_6FYolQth      5.0000  0.0  \n",
       "4   Trade_Ih7aGYPH   Acc_6FYolQth      5.1650  0.0  \n",
       "5   Trade_0LtSHdIY   Acc_6FYolQth      5.0000  0.0  \n",
       "6   Trade_V2iHtgjv   Acc_6FYolQth      5.2000  0.0  \n",
       "7   Trade_IfTMl7VW   Acc_6FYolQth      5.2300  0.0  \n",
       "8   Trade_bknV2DhH   Acc_6FYolQth      9.2875  0.0  \n",
       "9   Trade_sFdUk0Ji   Acc_6FYolQth      5.1500  0.0  \n",
       "10  Trade_806H7Z5V   Acc_6FYolQth      5.0000  0.0  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order realorder_id Order_Erp8lXjn datetime:2017-01-23 09:31:00 code:000002 amount:1000 price:20.74 towards:1 btype:stock_cn order_id:Order_Erp8lXjn account:Acc_6FYolQth status:300 >\n",
      "< QA_Order realorder_id Order_djeyQvoq datetime:2017-01-23 09:31:00 code:000004 amount:1000 price:37.56 towards:1 btype:stock_cn order_id:Order_djeyQvoq account:Acc_6FYolQth status:300 >\n",
      "< QA_Order realorder_id Order_Wr3VBIxR datetime:2017-01-24 09:31:00 code:000002 amount:1000 price:20.69 towards:1 btype:stock_cn order_id:Order_Wr3VBIxR account:Acc_6FYolQth status:300 >\n"
     ]
    }
   ],
   "source": [
    "b=QA.QA_Risk(a_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "code\n",
       "000001    3000.0\n",
       "000002    9000.0\n",
       "000004    3000.0\n",
       "Name: amount, dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-04 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code                                000001  000002  000004\n",
       "datetime            account_cookie                        \n",
       "2017-01-04 15:00:00 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-05 15:00:00 Acc_6FYolQth       0.0  1000.0  1000.0\n",
       "2017-01-06 15:00:00 Acc_6FYolQth    1000.0     0.0     0.0\n",
       "2017-01-09 15:00:00 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-12 15:00:00 Acc_6FYolQth    1000.0     0.0     0.0\n",
       "2017-01-17 15:00:00 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-18 15:00:00 Acc_6FYolQth       0.0  1000.0  1000.0\n",
       "2017-01-19 15:00:00 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-20 15:00:00 Acc_6FYolQth    1000.0  1000.0     0.0\n",
       "2017-01-23 15:00:00 Acc_6FYolQth       0.0  1000.0  1000.0\n",
       "2017-01-24 15:00:00 Acc_6FYolQth       0.0  1000.0     0.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.trade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>4000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>7000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code                       000001  000002  000004\n",
       "date       account_cookie                        \n",
       "2017-01-04 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-05 Acc_6FYolQth       0.0  2000.0  1000.0\n",
       "2017-01-06 Acc_6FYolQth    1000.0  2000.0  1000.0\n",
       "2017-01-09 Acc_6FYolQth    1000.0  3000.0  1000.0\n",
       "2017-01-12 Acc_6FYolQth    2000.0  3000.0  1000.0\n",
       "2017-01-17 Acc_6FYolQth    2000.0  4000.0  1000.0\n",
       "2017-01-18 Acc_6FYolQth    2000.0  5000.0  2000.0\n",
       "2017-01-19 Acc_6FYolQth    2000.0  6000.0  2000.0\n",
       "2017-01-20 Acc_6FYolQth    3000.0  7000.0  2000.0\n",
       "2017-01-23 Acc_6FYolQth    3000.0  8000.0  3000.0\n",
       "2017-01-24 Acc_6FYolQth    3000.0  9000.0  3000.0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "< QA_Order realorder_id Order_2uIzK1Nx datetime:2018-06-27 09:31:00 code:000001 amount:2000 price:9.09 towards:-1 btype:stock_cn order_id:Order_2uIzK1Nx account:Acc_6FYolQth status:300 >"
     ]
    }
   ],
   "source": [
    "market.insert_order(account_cookie=a_1.account_cookie, amount=2000, price=None, amount_model=QA.AMOUNT_MODEL.BY_AMOUNT, time='2018-06-27', code='000001',\n",
    "                    order_model=QA.ORDER_MODEL.CLOSE, towards=QA.ORDER_DIRECTION.SELL, market_type=QA.MARKET_TYPE.STOCK_CN,\n",
    "                    frequence=QA.FREQUENCE.DAY, broker_name=QA.BROKER_TYPE.BACKETEST)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===== SETTLED None =====\n"
     ]
    }
   ],
   "source": [
    "market._settle(QA.BROKER_TYPE.BACKETEST)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>4000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>7000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-27</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code                       000001  000002  000004\n",
       "date       account_cookie                        \n",
       "2017-01-04 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-05 Acc_6FYolQth       0.0  2000.0  1000.0\n",
       "2017-01-06 Acc_6FYolQth    1000.0  2000.0  1000.0\n",
       "2017-01-09 Acc_6FYolQth    1000.0  3000.0  1000.0\n",
       "2017-01-12 Acc_6FYolQth    2000.0  3000.0  1000.0\n",
       "2017-01-17 Acc_6FYolQth    2000.0  4000.0  1000.0\n",
       "2017-01-18 Acc_6FYolQth    2000.0  5000.0  2000.0\n",
       "2017-01-19 Acc_6FYolQth    2000.0  6000.0  2000.0\n",
       "2017-01-20 Acc_6FYolQth    3000.0  7000.0  2000.0\n",
       "2017-01-23 Acc_6FYolQth    3000.0  8000.0  3000.0\n",
       "2017-01-24 Acc_6FYolQth    3000.0  9000.0  3000.0\n",
       "2018-06-27 Acc_6FYolQth    1000.0  9000.0  3000.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=QA.QA_fetch_stock_day_adv(['000001','000002','000004','000007'],'2017-01-03','2017-01-26')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "      <th>000007</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>9.16</td>\n",
       "      <td>20.73</td>\n",
       "      <td>44.45</td>\n",
       "      <td>26.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>9.16</td>\n",
       "      <td>20.85</td>\n",
       "      <td>44.70</td>\n",
       "      <td>26.47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>9.17</td>\n",
       "      <td>20.93</td>\n",
       "      <td>44.44</td>\n",
       "      <td>26.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>9.13</td>\n",
       "      <td>20.64</td>\n",
       "      <td>43.96</td>\n",
       "      <td>25.45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>9.15</td>\n",
       "      <td>20.66</td>\n",
       "      <td>43.01</td>\n",
       "      <td>25.09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>9.15</td>\n",
       "      <td>20.58</td>\n",
       "      <td>43.25</td>\n",
       "      <td>24.79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>9.14</td>\n",
       "      <td>20.40</td>\n",
       "      <td>42.45</td>\n",
       "      <td>24.85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>9.15</td>\n",
       "      <td>NaN</td>\n",
       "      <td>42.05</td>\n",
       "      <td>24.61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-13</th>\n",
       "      <td>9.16</td>\n",
       "      <td>21.81</td>\n",
       "      <td>41.00</td>\n",
       "      <td>23.81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-16</th>\n",
       "      <td>9.14</td>\n",
       "      <td>21.00</td>\n",
       "      <td>38.26</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <td>9.15</td>\n",
       "      <td>20.80</td>\n",
       "      <td>37.37</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <td>9.17</td>\n",
       "      <td>20.92</td>\n",
       "      <td>37.15</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <td>9.18</td>\n",
       "      <td>20.60</td>\n",
       "      <td>35.69</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <td>9.22</td>\n",
       "      <td>20.68</td>\n",
       "      <td>36.48</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <td>9.22</td>\n",
       "      <td>20.74</td>\n",
       "      <td>37.56</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <td>9.27</td>\n",
       "      <td>20.69</td>\n",
       "      <td>38.63</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-25</th>\n",
       "      <td>9.26</td>\n",
       "      <td>20.61</td>\n",
       "      <td>38.25</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-26</th>\n",
       "      <td>9.33</td>\n",
       "      <td>20.68</td>\n",
       "      <td>38.29</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code        000001  000002  000004  000007\n",
       "date                                      \n",
       "2017-01-03    9.16   20.73   44.45   26.10\n",
       "2017-01-04    9.16   20.85   44.70   26.47\n",
       "2017-01-05    9.17   20.93   44.44   26.24\n",
       "2017-01-06    9.13   20.64   43.96   25.45\n",
       "2017-01-09    9.15   20.66   43.01   25.09\n",
       "2017-01-10    9.15   20.58   43.25   24.79\n",
       "2017-01-11    9.14   20.40   42.45   24.85\n",
       "2017-01-12    9.15     NaN   42.05   24.61\n",
       "2017-01-13    9.16   21.81   41.00   23.81\n",
       "2017-01-16    9.14   21.00   38.26     NaN\n",
       "2017-01-17    9.15   20.80   37.37     NaN\n",
       "2017-01-18    9.17   20.92   37.15     NaN\n",
       "2017-01-19    9.18   20.60   35.69     NaN\n",
       "2017-01-20    9.22   20.68   36.48     NaN\n",
       "2017-01-23    9.22   20.74   37.56     NaN\n",
       "2017-01-24    9.27   20.69   38.63     NaN\n",
       "2017-01-25    9.26   20.61   38.25     NaN\n",
       "2017-01-26    9.33   20.68   38.29     NaN"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "md=data.pivot('close')\n",
    "md"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-01-04 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.85</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>979144.7875</td>\n",
       "      <td>Order_xNF7jTOS</td>\n",
       "      <td>Trade_2pDrT1iL</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2125</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-01-05 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.93</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>958209.5550</td>\n",
       "      <td>Order_HSXGokPv</td>\n",
       "      <td>Trade_PVO3Twz9</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2325</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-01-05 15:00:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>44.44</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>913758.4450</td>\n",
       "      <td>Order_OsaBy2zu</td>\n",
       "      <td>Trade_1qQutHdA</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>11.1100</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-01-06 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.13</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>904623.4450</td>\n",
       "      <td>Order_07nBUeLG</td>\n",
       "      <td>Trade_r4LNcOPy</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.0000</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-01-09 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.66</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>883958.2800</td>\n",
       "      <td>Order_2SacPF4Z</td>\n",
       "      <td>Trade_Ih7aGYPH</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.1650</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-01-12 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>874803.2800</td>\n",
       "      <td>Order_NvhOeWqH</td>\n",
       "      <td>Trade_0LtSHdIY</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.0000</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2017-01-17 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.80</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>853998.0800</td>\n",
       "      <td>Order_MZcslPuQ</td>\n",
       "      <td>Trade_V2iHtgjv</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2000</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2017-01-18 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.92</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>833072.8500</td>\n",
       "      <td>Order_KfpYI4M0</td>\n",
       "      <td>Trade_IfTMl7VW</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.2300</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2017-01-18 15:00:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.15</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>795913.5625</td>\n",
       "      <td>Order_jS9se3y5</td>\n",
       "      <td>Trade_bknV2DhH</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>9.2875</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2017-01-19 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.60</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>775308.4125</td>\n",
       "      <td>Order_AzHMUgxZ</td>\n",
       "      <td>Trade_sFdUk0Ji</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.1500</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2017-01-20 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.22</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>766083.4125</td>\n",
       "      <td>Order_dEsC8GmL</td>\n",
       "      <td>Trade_806H7Z5V</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.0000</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2017-01-20 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.68</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>745398.2425</td>\n",
       "      <td>Order_E0NeS1Ci</td>\n",
       "      <td>Trade_zLnpeC2V</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.1700</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2017-01-23 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.74</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>724653.0575</td>\n",
       "      <td>Order_Erp8lXjn</td>\n",
       "      <td>Trade_3oqO6JBt</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.1850</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2017-01-23 15:00:00</td>\n",
       "      <td>000004</td>\n",
       "      <td>37.56</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>687083.6675</td>\n",
       "      <td>Order_djeyQvoq</td>\n",
       "      <td>Trade_LYfArK12</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>9.3900</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2017-01-24 15:00:00</td>\n",
       "      <td>000002</td>\n",
       "      <td>20.69</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>666388.4950</td>\n",
       "      <td>Order_Wr3VBIxR</td>\n",
       "      <td>Trade_2IGE6Tqy</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.1725</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2018-06-27 15:00:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.09</td>\n",
       "      <td>-2000.0</td>\n",
       "      <td>684536.2250</td>\n",
       "      <td>Order_2uIzK1Nx</td>\n",
       "      <td>Trade_V4l1zXLE</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "      <td>5.0000</td>\n",
       "      <td>27.27</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               datetime    code  price  amount         cash        order_id  \\\n",
       "0   2017-01-04 15:00:00  000002  20.85  1000.0  979144.7875  Order_xNF7jTOS   \n",
       "1   2017-01-05 15:00:00  000002  20.93  1000.0  958209.5550  Order_HSXGokPv   \n",
       "2   2017-01-05 15:00:00  000004  44.44  1000.0  913758.4450  Order_OsaBy2zu   \n",
       "3   2017-01-06 15:00:00  000001   9.13  1000.0  904623.4450  Order_07nBUeLG   \n",
       "4   2017-01-09 15:00:00  000002  20.66  1000.0  883958.2800  Order_2SacPF4Z   \n",
       "5   2017-01-12 15:00:00  000001   9.15  1000.0  874803.2800  Order_NvhOeWqH   \n",
       "6   2017-01-17 15:00:00  000002  20.80  1000.0  853998.0800  Order_MZcslPuQ   \n",
       "7   2017-01-18 15:00:00  000002  20.92  1000.0  833072.8500  Order_KfpYI4M0   \n",
       "8   2017-01-18 15:00:00  000004  37.15  1000.0  795913.5625  Order_jS9se3y5   \n",
       "9   2017-01-19 15:00:00  000002  20.60  1000.0  775308.4125  Order_AzHMUgxZ   \n",
       "10  2017-01-20 15:00:00  000001   9.22  1000.0  766083.4125  Order_dEsC8GmL   \n",
       "11  2017-01-20 15:00:00  000002  20.68  1000.0  745398.2425  Order_E0NeS1Ci   \n",
       "12  2017-01-23 15:00:00  000002  20.74  1000.0  724653.0575  Order_Erp8lXjn   \n",
       "13  2017-01-23 15:00:00  000004  37.56  1000.0  687083.6675  Order_djeyQvoq   \n",
       "14  2017-01-24 15:00:00  000002  20.69  1000.0  666388.4950  Order_Wr3VBIxR   \n",
       "15  2018-06-27 15:00:00  000001   9.09 -2000.0  684536.2250  Order_2uIzK1Nx   \n",
       "\n",
       "          trade_id account_cookie  commission    tax  \n",
       "0   Trade_2pDrT1iL   Acc_6FYolQth      5.2125   0.00  \n",
       "1   Trade_PVO3Twz9   Acc_6FYolQth      5.2325   0.00  \n",
       "2   Trade_1qQutHdA   Acc_6FYolQth     11.1100   0.00  \n",
       "3   Trade_r4LNcOPy   Acc_6FYolQth      5.0000   0.00  \n",
       "4   Trade_Ih7aGYPH   Acc_6FYolQth      5.1650   0.00  \n",
       "5   Trade_0LtSHdIY   Acc_6FYolQth      5.0000   0.00  \n",
       "6   Trade_V2iHtgjv   Acc_6FYolQth      5.2000   0.00  \n",
       "7   Trade_IfTMl7VW   Acc_6FYolQth      5.2300   0.00  \n",
       "8   Trade_bknV2DhH   Acc_6FYolQth      9.2875   0.00  \n",
       "9   Trade_sFdUk0Ji   Acc_6FYolQth      5.1500   0.00  \n",
       "10  Trade_806H7Z5V   Acc_6FYolQth      5.0000   0.00  \n",
       "11  Trade_zLnpeC2V   Acc_6FYolQth      5.1700   0.00  \n",
       "12  Trade_3oqO6JBt   Acc_6FYolQth      5.1850   0.00  \n",
       "13  Trade_LYfArK12   Acc_6FYolQth      9.3900   0.00  \n",
       "14  Trade_2IGE6Tqy   Acc_6FYolQth      5.1725   0.00  \n",
       "15  Trade_V4l1zXLE   Acc_6FYolQth      5.0000  27.27  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>datetime</th>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-04 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>979145</td>\n",
       "      <td>2017-01-04 15:00:00</td>\n",
       "      <td>2017-01-04</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">2017-01-05 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>958210</td>\n",
       "      <td>2017-01-05 15:00:00</td>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>913758</td>\n",
       "      <td>2017-01-05 15:00:00</td>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>904623</td>\n",
       "      <td>2017-01-06 15:00:00</td>\n",
       "      <td>2017-01-06</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>883958</td>\n",
       "      <td>2017-01-09 15:00:00</td>\n",
       "      <td>2017-01-09</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>874803</td>\n",
       "      <td>2017-01-12 15:00:00</td>\n",
       "      <td>2017-01-12</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>853998</td>\n",
       "      <td>2017-01-17 15:00:00</td>\n",
       "      <td>2017-01-17</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">2017-01-18 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>833073</td>\n",
       "      <td>2017-01-18 15:00:00</td>\n",
       "      <td>2017-01-18</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>795914</td>\n",
       "      <td>2017-01-18 15:00:00</td>\n",
       "      <td>2017-01-18</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>775308</td>\n",
       "      <td>2017-01-19 15:00:00</td>\n",
       "      <td>2017-01-19</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">2017-01-20 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>766083</td>\n",
       "      <td>2017-01-20 15:00:00</td>\n",
       "      <td>2017-01-20</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>745398</td>\n",
       "      <td>2017-01-20 15:00:00</td>\n",
       "      <td>2017-01-20</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">2017-01-23 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>724653</td>\n",
       "      <td>2017-01-23 15:00:00</td>\n",
       "      <td>2017-01-23</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>687084</td>\n",
       "      <td>2017-01-23 15:00:00</td>\n",
       "      <td>2017-01-23</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>666388</td>\n",
       "      <td>2017-01-24 15:00:00</td>\n",
       "      <td>2017-01-24</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-27 15:00:00</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>684536</td>\n",
       "      <td>2018-06-27 15:00:00</td>\n",
       "      <td>2018-06-27</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      cash             datetime       date  \\\n",
       "datetime            account_cookie                                           \n",
       "2017-01-04 15:00:00 Acc_6FYolQth    979145  2017-01-04 15:00:00 2017-01-04   \n",
       "2017-01-05 15:00:00 Acc_6FYolQth    958210  2017-01-05 15:00:00 2017-01-05   \n",
       "                    Acc_6FYolQth    913758  2017-01-05 15:00:00 2017-01-05   \n",
       "2017-01-06 15:00:00 Acc_6FYolQth    904623  2017-01-06 15:00:00 2017-01-06   \n",
       "2017-01-09 15:00:00 Acc_6FYolQth    883958  2017-01-09 15:00:00 2017-01-09   \n",
       "2017-01-12 15:00:00 Acc_6FYolQth    874803  2017-01-12 15:00:00 2017-01-12   \n",
       "2017-01-17 15:00:00 Acc_6FYolQth    853998  2017-01-17 15:00:00 2017-01-17   \n",
       "2017-01-18 15:00:00 Acc_6FYolQth    833073  2017-01-18 15:00:00 2017-01-18   \n",
       "                    Acc_6FYolQth    795914  2017-01-18 15:00:00 2017-01-18   \n",
       "2017-01-19 15:00:00 Acc_6FYolQth    775308  2017-01-19 15:00:00 2017-01-19   \n",
       "2017-01-20 15:00:00 Acc_6FYolQth    766083  2017-01-20 15:00:00 2017-01-20   \n",
       "                    Acc_6FYolQth    745398  2017-01-20 15:00:00 2017-01-20   \n",
       "2017-01-23 15:00:00 Acc_6FYolQth    724653  2017-01-23 15:00:00 2017-01-23   \n",
       "                    Acc_6FYolQth    687084  2017-01-23 15:00:00 2017-01-23   \n",
       "2017-01-24 15:00:00 Acc_6FYolQth    666388  2017-01-24 15:00:00 2017-01-24   \n",
       "2018-06-27 15:00:00 Acc_6FYolQth    684536  2018-06-27 15:00:00 2018-06-27   \n",
       "\n",
       "                                   account_cookie  \n",
       "datetime            account_cookie                 \n",
       "2017-01-04 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-05 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "                    Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-06 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-09 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-12 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-17 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-18 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "                    Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-19 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-20 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "                    Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-23 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "                    Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-24 15:00:00 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2018-06-27 15:00:00 Acc_6FYolQth     Acc_6FYolQth  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.cash_table\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>cash</th>\n",
       "      <th>datetime</th>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>979145</td>\n",
       "      <td>2017-01-04 15:00:00</td>\n",
       "      <td>2017-01-04</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>913758</td>\n",
       "      <td>2017-01-05 15:00:00</td>\n",
       "      <td>2017-01-05</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>904623</td>\n",
       "      <td>2017-01-06 15:00:00</td>\n",
       "      <td>2017-01-06</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>883958</td>\n",
       "      <td>2017-01-09 15:00:00</td>\n",
       "      <td>2017-01-09</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>874803</td>\n",
       "      <td>2017-01-12 15:00:00</td>\n",
       "      <td>2017-01-12</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>853998</td>\n",
       "      <td>2017-01-17 15:00:00</td>\n",
       "      <td>2017-01-17</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>795914</td>\n",
       "      <td>2017-01-18 15:00:00</td>\n",
       "      <td>2017-01-18</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>775308</td>\n",
       "      <td>2017-01-19 15:00:00</td>\n",
       "      <td>2017-01-19</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>745398</td>\n",
       "      <td>2017-01-20 15:00:00</td>\n",
       "      <td>2017-01-20</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>687084</td>\n",
       "      <td>2017-01-23 15:00:00</td>\n",
       "      <td>2017-01-23</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>666388</td>\n",
       "      <td>2017-01-24 15:00:00</td>\n",
       "      <td>2017-01-24</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-27</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>684536</td>\n",
       "      <td>2018-06-27 15:00:00</td>\n",
       "      <td>2018-06-27</td>\n",
       "      <td>Acc_6FYolQth</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                             cash             datetime       date  \\\n",
       "date       account_cookie                                           \n",
       "2017-01-04 Acc_6FYolQth    979145  2017-01-04 15:00:00 2017-01-04   \n",
       "2017-01-05 Acc_6FYolQth    913758  2017-01-05 15:00:00 2017-01-05   \n",
       "2017-01-06 Acc_6FYolQth    904623  2017-01-06 15:00:00 2017-01-06   \n",
       "2017-01-09 Acc_6FYolQth    883958  2017-01-09 15:00:00 2017-01-09   \n",
       "2017-01-12 Acc_6FYolQth    874803  2017-01-12 15:00:00 2017-01-12   \n",
       "2017-01-17 Acc_6FYolQth    853998  2017-01-17 15:00:00 2017-01-17   \n",
       "2017-01-18 Acc_6FYolQth    795914  2017-01-18 15:00:00 2017-01-18   \n",
       "2017-01-19 Acc_6FYolQth    775308  2017-01-19 15:00:00 2017-01-19   \n",
       "2017-01-20 Acc_6FYolQth    745398  2017-01-20 15:00:00 2017-01-20   \n",
       "2017-01-23 Acc_6FYolQth    687084  2017-01-23 15:00:00 2017-01-23   \n",
       "2017-01-24 Acc_6FYolQth    666388  2017-01-24 15:00:00 2017-01-24   \n",
       "2018-06-27 Acc_6FYolQth    684536  2018-06-27 15:00:00 2018-06-27   \n",
       "\n",
       "                          account_cookie  \n",
       "date       account_cookie                 \n",
       "2017-01-04 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-05 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-06 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-09 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-12 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-17 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-18 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-19 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-20 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-23 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2017-01-24 Acc_6FYolQth     Acc_6FYolQth  \n",
       "2018-06-27 Acc_6FYolQth     Acc_6FYolQth  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>4000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>7000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-27</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code                       000001  000002  000004\n",
       "date       account_cookie                        \n",
       "2017-01-04 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-05 Acc_6FYolQth       0.0  2000.0  1000.0\n",
       "2017-01-06 Acc_6FYolQth    1000.0  2000.0  1000.0\n",
       "2017-01-09 Acc_6FYolQth    1000.0  3000.0  1000.0\n",
       "2017-01-12 Acc_6FYolQth    2000.0  3000.0  1000.0\n",
       "2017-01-17 Acc_6FYolQth    2000.0  4000.0  1000.0\n",
       "2017-01-18 Acc_6FYolQth    2000.0  5000.0  2000.0\n",
       "2017-01-19 Acc_6FYolQth    2000.0  6000.0  2000.0\n",
       "2017-01-20 Acc_6FYolQth    3000.0  7000.0  2000.0\n",
       "2017-01-23 Acc_6FYolQth    3000.0  8000.0  3000.0\n",
       "2017-01-24 Acc_6FYolQth    3000.0  9000.0  3000.0\n",
       "2018-06-27 Acc_6FYolQth    1000.0  9000.0  3000.0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['000002', '000004', '000001']"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.history_table.code.unique().tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex(levels=[['2017-01-04', '2017-01-05', '2017-01-06', '2017-01-09', '2017-01-12', '2017-01-17', '2017-01-18', '2017-01-19', '2017-01-20', '2017-01-23', '2017-01-24', '2018-06-27'], ['Acc_6FYolQth']],\n",
       "           labels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],\n",
       "           names=['date', 'account_cookie'])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "market_data=QA.QA_fetch_stock_day_adv(list(data.columns),data.index[0][0],data.index[-1][0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_DataStruct_Stock_day with 3 securities >"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "market_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['000004', '000001', '000002']"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(set([item[1] for item in a_1.history]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>000001</th>\n",
       "      <th>000002</th>\n",
       "      <th>000004</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>0.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>2000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>3000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-17</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>4000.0</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-18</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-19</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>2000.0</td>\n",
       "      <td>6000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-20</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>7000.0</td>\n",
       "      <td>2000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-23</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>8000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-24</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>3000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-06-27</th>\n",
       "      <th>Acc_6FYolQth</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "code                       000001  000002  000004\n",
       "date       account_cookie                        \n",
       "2017-01-04 Acc_6FYolQth       0.0  1000.0     0.0\n",
       "2017-01-05 Acc_6FYolQth       0.0  2000.0  1000.0\n",
       "2017-01-06 Acc_6FYolQth    1000.0  2000.0  1000.0\n",
       "2017-01-09 Acc_6FYolQth    1000.0  3000.0  1000.0\n",
       "2017-01-12 Acc_6FYolQth    2000.0  3000.0  1000.0\n",
       "2017-01-17 Acc_6FYolQth    2000.0  4000.0  1000.0\n",
       "2017-01-18 Acc_6FYolQth    2000.0  5000.0  2000.0\n",
       "2017-01-19 Acc_6FYolQth    2000.0  6000.0  2000.0\n",
       "2017-01-20 Acc_6FYolQth    3000.0  7000.0  2000.0\n",
       "2017-01-23 Acc_6FYolQth    3000.0  8000.0  3000.0\n",
       "2017-01-24 Acc_6FYolQth    3000.0  9000.0  3000.0\n",
       "2018-06-27 Acc_6FYolQth    1000.0  9000.0  3000.0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_1.daily_hold"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "date        account_cookie\n",
       "2017-01-04  Acc_6FYolQth      999309\n",
       "2017-01-05  Acc_6FYolQth      998681\n",
       "2017-01-06  Acc_6FYolQth      997504\n",
       "2017-01-09  Acc_6FYolQth      995927\n",
       "2017-01-12  Acc_6FYolQth      934890\n",
       "2017-01-17  Acc_6FYolQth      989867\n",
       "2017-01-18  Acc_6FYolQth      989448\n",
       "2017-01-19  Acc_6FYolQth      984317\n",
       "2017-01-20  Acc_6FYolQth      985617\n",
       "2017-01-23  Acc_6FYolQth      987486\n",
       "2017-01-24  Acc_6FYolQth      989771\n",
       "2018-06-27  Acc_6FYolQth      968276\n",
       "dtype: object"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(market_data.to_qfq().pivot('close')*a_1.daily_hold).sum(axis=1)+a_1.daily_cash.set_index('date').cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r=QA.QA_Risk(a_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r.market_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "r.assets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
